/**
 * 不安全的取钱
 */
public class UnSafeBank {
    public static void main(String[] args) {
        Account account = new Account(100, "结婚基金");
        new Thread(new WithdrawMoney(account, 50), "你").start();
        new Thread(new WithdrawMoney(account, 100), "女朋友").start();
    }
}

class Account {
    int money = 0;
    String name = "";

    public Account(int money, String name) {
        this.money = money;
        this.name = name;
    }
}

class WithdrawMoney implements Runnable {
    Account account;
    int drawingMoney;

    public WithdrawMoney(Account account, int drawingMoney) {
        this.account = account;
        this.drawingMoney = drawingMoney;
    }

    @Override
    public void run() {
        if (account.money < drawingMoney) {
            System.out.println(Thread.currentThread().getName() + "：钱不够了,取不了啊");
            return;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        account.money -= drawingMoney;
        System.out.println(account.name + "账户余额为：" + account.money);
        System.out.println(Thread.currentThread().getName() + "手里的钱为： " + drawingMoney);
    }
}